{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "——————\n",
    "\n",
    "*日期：2022年10月26日\n",
    "\n",
    "*课程：python\n",
    "\n",
    "*记录人：林锦纯\n",
    "\n",
    "——————"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 购物车准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\"自行车 299\"，\"手机 3000\",\"电脑 4000\",\"相机 5000\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list =[\n",
    "    [\"自行车\", \"299\"],\n",
    "    [\"手机\",\"3000\"],\n",
    "    [\"电脑\",\"4000\"],\n",
    "    [\"相机\",\"50000\"]\n",
    "]\n",
    "\n",
    "\n",
    "shopping_car = []\n",
    "\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "while Ture:\n",
    "    print(\"-----------商品列表-----------\")  \n",
    "    for i in range(4):\n",
    "        print(\"商品编号\",+str(i),product_list[i])\n",
    "    user_choice = input(\"请输入商品编号：\") \n",
    "    #情景一:用户输入了商品编号：shopping\n",
    "    if user_choice.isdigit():\n",
    "        #判断钱够不够，商品是谁？==> product_list[user_choice][1]\n",
    "        if Alipay >= product_list[int(user_choice)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_choice)][1]  #买完商品剩余的钱\n",
    "            print(\"您买的商品已增加到购物车~~您的余额还有:\",Alipay)\n",
    "        else:\n",
    "            print(\"您的余额已不足，请更换支付方式\")\n",
    "    #情景二：用户输入”q”,退出购买\n",
    "    elif user_chioce == \"q\":\n",
    "        print(\"您的购物车：\"，shopping_car)\n",
    "        break\n",
    "    #情景三：\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入有误，请重新尝试\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shopping_car = [[\"自行车\", \"299\"],[\"手机\",\"3000\"],[\"电脑\",\"4000\"],[\"相机\",\"50000\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (<ipython-input-25-ea036189b27b>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-25-ea036189b27b>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    print()\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "Alipay = input(\"请输入余额：4001\")\n",
    "     print()   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "#情景1：用户输入了商品编号：shopping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入商品编号：2\n"
     ]
    }
   ],
   "source": [
    "user_choice = input(\"请输入商品编号：\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 0，1，2，3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-30-8ebf007968a7>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-30-8ebf007968a7>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    if Alipay > shopping_car.pop(product_list[user_choices[1]]),Alipay - shopping_car.pop(product_list[user_choices[1]])\u001b[0m\n\u001b[1;37m                                                               ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "if Alipay > shopping_car.pop(product_list[user_choices[1]]),Alipay - shopping_car.pop(product_list[user_choices[1]])\n",
    "   shopping_car.append(product_list[user_choice])\n",
    "else print(\"您的余额已不足，请更换支付方式\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#情景2：用户输入“q”，退出购买\n",
    "print(shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyautogui\n",
      "  Downloading https://files.pythonhosted.org/packages/f0/76/7a0ec1013bc3559b7438f6773cba05ffaec600b8989be2d621a144e39b50/PyAutoGUI-0.9.53.tar.gz (59kB)\n",
      "Collecting pymsgbox (from pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/7d/ff/4c6f31a4f08979f12a663f2aeb6c8b765d3bd592e66eaaac445f547bb875/PyMsgBox-1.0.9.tar.gz\n",
      "  Installing build dependencies: started\n",
      "  Installing build dependencies: finished with status 'done'\n",
      "Collecting PyTweening>=1.0.1 (from pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/e9/4f/acb6a2d95260a4377885e40c167fd5df587630696a6a7934675f86aebb06/pytweening-1.0.4.tar.gz\n",
      "Collecting pyscreeze>=0.1.21 (from pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/75/23/3edc5ee974fb3994a38095056483b5d4b82b32a81f029e8085a4b4c05317/PyScreeze-0.1.28.tar.gz\n",
      "  Installing build dependencies: started\n",
      "  Installing build dependencies: finished with status 'done'\n",
      "Collecting pygetwindow>=0.0.5 (from pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/e1/70/c7a4f46dbf06048c6d57d9489b8e0f9c4c3d36b7479f03c5ca97eaa2541d/PyGetWindow-0.0.9.tar.gz\n",
      "Collecting mouseinfo (from pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/28/fa/b2ba8229b9381e8f6381c1dcae6f4159a7f72349e414ed19cfbbd1817173/MouseInfo-0.1.3.tar.gz\n",
      "Requirement already satisfied: Pillow>=5.2.0 in c:\\programdata\\anaconda3\\lib\\site-packages (from pyscreeze>=0.1.21->pyautogui) (5.2.0)\n",
      "Collecting pyrect (from pygetwindow>=0.0.5->pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/cb/04/2ba023d5f771b645f7be0c281cdacdcd939fe13d1deb331fc5ed1a6b3a98/PyRect-0.2.0.tar.gz\n",
      "Collecting pyperclip (from mouseinfo->pyautogui)\n",
      "  Downloading https://files.pythonhosted.org/packages/a7/2c/4c64579f847bd5d539803c8b909e54ba087a79d01bb3aba433a95879a6c5/pyperclip-1.8.2.tar.gz\n",
      "Building wheels for collected packages: pyautogui, pymsgbox, PyTweening, pyscreeze, pygetwindow, mouseinfo, pyrect, pyperclip\n",
      "  Running setup.py bdist_wheel for pyautogui: started\n",
      "  Running setup.py bdist_wheel for pyautogui: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\e6\\42\\25\\1cfcc9efcbe856c3c61af95b718ed5a1a75f7759d3507f5129\n",
      "  Running setup.py bdist_wheel for pymsgbox: started\n",
      "  Running setup.py bdist_wheel for pymsgbox: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\16\\d7\\4e\\fffdd54b1cca86608b7655c9a2854890a38f955ce9532848cd\n",
      "  Running setup.py bdist_wheel for PyTweening: started\n",
      "  Running setup.py bdist_wheel for PyTweening: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\92\\e4\\6f\\97a6047bbaadddfc9b9f0eddd8630a54e984321e86eb91a66a\n",
      "  Running setup.py bdist_wheel for pyscreeze: started\n",
      "  Running setup.py bdist_wheel for pyscreeze: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\d8\\0d\\c6\\c465a511c8d3c7adca0517a718be579076071d9a79dfb1353a\n",
      "  Running setup.py bdist_wheel for pygetwindow: started\n",
      "  Running setup.py bdist_wheel for pygetwindow: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\4b\\c1\\c6\\89b4fb35adcbfe54c5e71e830330dc39cfa231b32dc62eed6b\n",
      "  Running setup.py bdist_wheel for mouseinfo: started\n",
      "  Running setup.py bdist_wheel for mouseinfo: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\eb\\81\\32\\4d7b345486dbc3f3ee45316f8f4cbdebafc1b5d1da3353b529\n",
      "  Running setup.py bdist_wheel for pyrect: started\n",
      "  Running setup.py bdist_wheel for pyrect: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\1c\\58\\58\\6d3c1d990db44aea7e233239f36536fc399f2aa104590922e8\n",
      "  Running setup.py bdist_wheel for pyperclip: started\n",
      "  Running setup.py bdist_wheel for pyperclip: finished with status 'done'\n",
      "  Stored in directory: C:\\Users\\PC\\AppData\\Local\\pip\\Cache\\wheels\\25\\af\\b8\\3407109267803f4015e1ee2ff23be0c8c19ce4008665931ee1\n",
      "Successfully built pyautogui pymsgbox PyTweening pyscreeze pygetwindow mouseinfo pyrect pyperclip\n",
      "Installing collected packages: pymsgbox, PyTweening, pyscreeze, pyrect, pygetwindow, pyperclip, mouseinfo, pyautogui\n",
      "Successfully installed PyTweening-1.0.4 mouseinfo-0.1.3 pyautogui-0.9.53 pygetwindow-0.0.9 pymsgbox-1.0.9 pyperclip-1.8.2 pyrect-0.2.0 pyscreeze-0.1.28\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.\n",
      "You are using pip version 10.0.1, however version 22.3 is available.\n",
      "You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n"
     ]
    }
   ],
   "source": [
    "!pip install pyautogui"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import pyautogui"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'pyautogui' has no attribute 'typevrite'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-34-677b2035cb34>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mpyautogui\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtypevrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'hello world!'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0.5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: module 'pyautogui' has no attribute 'typevrite'"
     ]
    }
   ],
   "source": [
    "time.sleep(10)\n",
    "pyautogui.typevrite('hello world!',0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#作业："
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
